import 'package:flutter/material.dart';

class AccountSettingPage extends StatefulWidget {
  const AccountSettingPage({Key key}) : super(key: key);

  @override
  _AccountSettingPageState createState() => _AccountSettingPageState();
}

class _AccountSettingPageState extends State<AccountSettingPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('账号设置'),
      ),
      body: Container(
        child: ListView(
          children: [
            bottomLine(6, Colors.grey[300]),
            accountItem('账号', false, content: '121321231@qq.com'),
            bottomLine(1, Colors.grey[300]),
            subtitleItem('绑定手机号', '绑定成功之后可以通过手机号快速登录',
                content: '去绑定', isShowArr: true),
            bottomLine(6, Colors.grey[300]),
            accountItem('头像', true, iconData: Icons.tag_faces_sharp),
            bottomLine(1, Colors.grey[300]),
            accountItem('昵称', true, content: '有态度的网友'),
            bottomLine(1, Colors.grey[300]),
            accountItem('生日', true, content: '1980-01-01'),
            bottomLine(1, Colors.grey[300]),
            accountItem('性别', true, content: '男'),
            bottomLine(6, Colors.grey[300]),
            subtitleItem('匿名更贴', '其他网友将不会看到你的用户名、头像和个人主页',
                content: '去绑定', isShowArr: false),
            bottomLine(1, Colors.grey[300]),
            accountItem('跟帖设备名称', true, content: '小米八'),
            bottomLine(1, Colors.grey[300]),
            accountItem('我的等级', true, content: 'LV0 跟帖局科员'),
            backButton(),
            btmButton(),
          ],
        ),
      ),
    );
  }

  Widget btmButton() {
    return Container(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Text(
            '永久注销账号',
            style: TextStyle(color: Colors.grey),
          ),
          Icon(Icons.keyboard_arrow_right_sharp, color: Colors.grey)
        ],
      ),
    );
  }

  Widget backButton() {
    return Container(
      padding: EdgeInsets.all(15),
      margin: EdgeInsets.all(15),
      child: InkWell(
          onTap: () {
            print('object');
          },
          splashColor: Colors.white,
          child: Container(
            padding: EdgeInsets.symmetric(vertical: 16),
            // width: 200,
            // height: 50,
            // color: Colors.red,
            decoration: BoxDecoration(
              color: Colors.red,
              borderRadius: BorderRadius.all(Radius.circular(30)),
              border: Border.all(
                width: 1,
              ),
            ),
            child: Center(
                child: Text(
              '登出',
              style: TextStyle(color: Colors.white, fontSize: 17),
            )),
          )),
    );
  }

  Widget bottomLine(double w, Color color) {
    return Divider(
      thickness: w,
      color: color,
    );
  }

  Widget subtitleItem(
    String title,
    String subTitle, {
    String content,
    bool isShowArr,
  }) {
    bool valuea = true;
    return Container(
      padding: EdgeInsets.only(left: 15, right: 15, top: 10, bottom: 10),
      child: Row(
        // mainAxisAlignment: MainAxisAlignment.start,
        children: [
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                title,
                style: TextStyle(fontSize: 17, color: Colors.black),
              ),
              SizedBox(
                height: 3,
              ),
              Text(
                subTitle,
                style: TextStyle(fontSize: 13, color: Colors.grey),
              )
            ],
          ),
          Expanded(child: Container()),
          isShowArr
              ? Padding(
                  padding: EdgeInsets.only(left: 10),
                  child: Row(
                    children: [
                      Text(
                        content,
                        style: TextStyle(color: Colors.red, fontSize: 17),
                      ),
                      Padding(
                        padding: const EdgeInsets.only(left: 10),
                        child: Icon(
                          Icons.chevron_right,
                          color: Colors.grey,
                          size: 15,
                        ),
                      )
                    ],
                  ),
                )
              : Container(
                  child: Switch(
                  activeColor: Colors.red,
                  activeTrackColor: Colors.yellow,
                  inactiveThumbColor: Colors.pink[200],
                  inactiveTrackColor: Colors.black,
                  // activeThumbImage: AssetImage('images/aa.jpg'),?
                  // dragStartBehavior: DragStartBehavior.start,
                  value: valuea,
                  onChanged: (bool v) {
                    setState(() {
                      valuea = v;
                    });
                  },
                ))
        ],
      ),
    );
  }

  Widget accountItem(String tip, bool isShowArr,
      {String content, IconData iconData}) {
    bool isShowIcon = false;
    if (iconData != null) {
      isShowIcon = true;
    } else {}
    return Container(
      padding: EdgeInsets.only(left: 15, right: 15, top: 10, bottom: 10),
      child: Row(
        children: [
          Container(
            child: Text(
              tip,
              style: TextStyle(color: Colors.black, fontSize: 17),
            ),
          ),
          Expanded(
            child: Container(),
          ),
          Row(
            children: [
              isShowIcon
                  ? Padding(
                      padding: const EdgeInsets.only(right: 10),
                      child: Icon(iconData),
                    )
                  : Padding(
                      padding: const EdgeInsets.only(right: 10),
                      child: Text(
                        content,
                        style: TextStyle(fontSize: 17, color: Colors.grey),
                      ),
                    ),
              isShowArr
                  ? Icon(
                      Icons.arrow_forward_ios_sharp,
                      size: 15,
                      color: Colors.grey,
                    )
                  : Container()
            ],
          )
        ],
      ),
    );
  }
}
